/**
 * Created by zzy on 2016/12/8.
 */
var $ = require('jquery');
require('easyui');
require('layout/uiJs');
var $alert = require("libs/alert");
var $confirm = require("libs/confirm");
var isSale = require('libs/user-type').isSale;
$(function () {
    $('#ft').show();

    $('#search').on('click',function () {
        var formData = $('#searchForm').serializeObject();
        formData.starDate = $('#startDt').data('utc0');
        formData.endDate = $('#endDt').data('utc0');
        formData.tradeType = 'charge';
        formData.scene = 'Ledger';
        $('#rechargeTable').datagrid('load',formData);
    });
    $(document).on('click','a[name=entDetail]',function () {
        window.parent.tabOpen($(this).attr('ref'),'客户公司',true,true);
    });
    tableInit();
    function tableInit() {
        $('#rechargeTable').datagrid({
            url:'api/v1/p/mms/trade/list',
            border : false,
            height:$(window).height(),
            pagination : true,
            pageSize : 20,
            pageList : [ 20, 50,  100 ],
            emptyMsg : "暂无数据",
            singleSelect: true,
            rownumbers:true,
            queryParams: {
                scene: 'Ledger',
                tradeType: 'charge'
            },
            columns:[[
                {
                    field:'entName',
                    title:'客户名称',
                    width:'20%',
                    formatter:function (value,row,index) {
                        return "<a class='ellipsis' href='javascript:;' ref='company-detail?id="+row.entId+"' name='entDetail' title='"+value+"'>"+value+"</a>";
                    }
                },
                {
                    field:'currency',
                    title:'币种',
                    width:'17%'
                },{
                    field:'tradeDt',
                    title:'充值日期',
                    width:'20%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'subType',
                    title:'充值类型',
                    width:'15%',
                    formatter:function (value,row,index) {
                        switch (value){
                            case 'online': return '线上充值';
                            case 'offline': return '线下充值';
                            case 'exchange': return '兑换券';
                            case 'in': return '入库';
                            case 'out': return '出库';
                            case 'receive': return '揽收';
                            case 'o_in': return '海外入库';
                            case 'o_out': return '海外出库';
                            case 'o_store': return '海外仓储';
                            case 'o_photo': return '海外拍照';
                            case 'o_shelves': return '海外退货上架';
                            default: return '';
                        }
                    }
                },{
                    field:'totalAmount',
                    title:'充值金额',
                    width:'15%'
                },{
                    field:'afterBalance',
                    title:'期后金额',
                    width:'13%'
                }
            ]],
            loadFilter:function(data){
                if(data.code == '200'){
                    return data.data;
                }else{
                    return [];
                }
            },
            toolbar:"#tb"
        });
    }
});
